Skip to content

fix(unpickler): allow Alpha158/Alpha360 handlers and the standard dataset chain#2213

Open
genisis0x wants to merge 1 commit into
microsoft:mainfrom
genisis0x:fix/2130-pickle-safelist-alpha-handlers
Open

fix(unpickler): allow Alpha158/Alpha360 handlers and the standard dataset chain#2213
genisis0x wants to merge 1 commit into
microsoft:mainfrom
genisis0x:fix/2130-pickle-safelist-alpha-handlers

Conversation

@genisis0x
Copy link
Copy Markdown

Summary

  • Fixes UnpicklingError: Forbidden class: qlib.contrib.data.handler.Alpha158 #2130. The RestrictedUnpickler safelist landed by the recent security hardening (fix(security): address reported unsafe pickle.load usages #2099 / fix(security): restrict pickle deserialization to safe classes #2076 / fix(security): use RestrictedUnpickler in load_instance #2153) only covered the abstract DataHandler / DataHandlerLP classes plus StaticDataLoader. Any rolling workflow that pickles a real Dataset (the default for Rolling._train_rolling_tasks) walks into one of the contrib stock handlers and now crashes on reload:

    UnpicklingError: Forbidden class: qlib.contrib.data.handler.Alpha158.
    Only whitelisted classes are allowed for security reasons. ...
    

    Unrolling workflows happened to use a path that did not go through the restricted loader, which is why downgrading from 0.9.8.dev26 to 0.9.7 hid the issue.

  • Extend SAFE_PICKLE_CLASSES with the qlib-internal classes that sit on the standard recorder pickle graph:

    • The four shipped contrib handlers: Alpha158, Alpha158vwap, Alpha360, Alpha360vwap.
    • The dataset wrappers (Dataset, DatasetH, TSDatasetH) and the additional concrete loaders (DataLoader, DLWParser, QlibDataLoader, NestedDataLoader, DataLoaderDH).
    • Every concrete Processor defined in qlib.data.dataset.processor -- they appear in every realistic learn_processors / infer_processors chain.
  • These are all classes already shipped inside qlib itself, so adding them does not weaken the threat model the safelist was designed against (arbitrary code execution through externally-supplied pickle payloads).

Validation

  • uv run pytest tests/misc/test_pickle_safelist.py tests/misc/test_config_registered.py -- 13 passed (25 subtests).
  • uv run black qlib/utils/pickle_utils.py tests/misc/test_pickle_safelist.py -l 120 --check --diff -- clean.
  • uv run flake8 --ignore=E501,F541,E266,E402,W503,E731,E203 qlib/utils/pickle_utils.py -- clean.
  • End-to-end check: RestrictedUnpickler.find_class("qlib.contrib.data.handler", "Alpha158") now returns the real Alpha158 class object instead of raising, and a payload containing an unrelated unknown class is still rejected.

Fixes #2130

…aset chain

The RestrictedUnpickler safelist introduced by the recent security
hardening (microsoft#2099 / microsoft#2076 / microsoft#2153) only covered the abstract
``DataHandler`` / ``DataHandlerLP`` classes plus ``StaticDataLoader``.
Any rolling workflow that pickles a real Dataset (the default for
``Rolling._train_rolling_tasks``) walks into one of the contrib stock
handlers and now crashes on reload (issue microsoft#2130):

    UnpicklingError: Forbidden class:
    qlib.contrib.data.handler.Alpha158. Only whitelisted classes
    are allowed for security reasons. ...

Unrolling workflows happened to use a path that did not go through the
restricted loader, which is why downgrading to 0.9.7 hid the issue.

Extend ``SAFE_PICKLE_CLASSES`` with the qlib-internal classes that sit
on the standard recorder pickle graph:

* The four shipped contrib handlers: ``Alpha158``, ``Alpha158vwap``,
  ``Alpha360``, ``Alpha360vwap``.
* The dataset wrappers (``Dataset``, ``DatasetH``, ``TSDatasetH``) and
  the additional concrete loaders (``DataLoader``, ``DLWParser``,
  ``QlibDataLoader``, ``NestedDataLoader``, ``DataLoaderDH``).
* Every concrete ``Processor`` defined in
  ``qlib.data.dataset.processor`` -- they show up in every realistic
  ``learn_processors`` / ``infer_processors`` chain.

These are all classes already shipped inside qlib itself, so adding
them does not weaken the threat model the safelist was designed
against (arbitrary code execution through external pickle payloads).

Add regression tests pinning each added entry plus an end-to-end check
that ``RestrictedUnpickler.find_class`` actually resolves ``Alpha158``
and that other unknown classes are still rejected.

Fixes microsoft#2130
@genisis0x
Copy link
Copy Markdown
Author

Reviewed the CLA, happy to sign.

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UnpicklingError: Forbidden class: qlib.contrib.data.handler.Alpha158

1 participant